package com.ly.honor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ly.honor.entity.User;
import com.ly.honor.entity.dto.UpdatePassDTO;
import com.ly.honor.exception.HonorException;
import com.ly.honor.service.UserService;
import com.ly.honor.mapper.UserMapper;
import com.ly.honor.util.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
* @author 17798
* @description 针对表【bs_user】的数据库操作Service实现
* @createDate 2023-03-21 16:00:51
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public void updatePasswordById(UpdatePassDTO updatePassDTO) {
        var id = updatePassDTO.getId();
        var user = userMapper.selectById(id);
        if(ObjectUtils.isEmpty(user)){
            throw new HonorException(ResultEnum.MESSAGE_INVALID);
        }
        if(!user.getPassword().equals(updatePassDTO.getOldPass())){
            throw new HonorException("原密码错误，请重新尝试");
        }
        user.setPassword(updatePassDTO.getPass());
        userMapper.updateById(user);
    }
}




